<template>
	<view>
		<view>
			<!--#ifdef APP-PLUS-->
			<view class="lz-status_bar">
				<view class="lz-top_view"></view>
			</view>
			<!--#endif-->
			<!-- #ifndef MP-WEIXIN -->
			<view class="kaoshi-head">
				<view class="kaoshi-head-top">
					<view class="kaoshi-head-left">
						<view class="iconfont icon-zuojiantou" @tap="$navigateBack"></view>
					</view>
					<view class="kaoshi-head-m">选择科目</view>
					<view class="kaoshi-head-right"></view>
				</view>
			</view>
			<!--#endif-->
		</view>
		<view class="kaoshi-subject">
			<view class="classifybox">
				<view class="classify" v-for="(item,index) in list" :key="index"
					:class="classifytype == index ? 'active' : ''" @tap="changeclassify(index,item.id)">
					<view class="classifytext" :class="classifytype == index ? 'active' : ''">{{item.subject_name}}</view>
				</view>
			</view>
			<view class="liebiaobox">
				<view class="class" v-for="(item,index) in classlist" :key="index">
					<view @tap="tap_handle_choice_subject(item)" class="" style="width: 100%;display: flex;align-items: center;justify-content: space-between;">
						<view :class="Subject_id == item.id ? 'active' : ''" class="classtext"
							>
							<view class="line"></view>
							<view class="text">{{item.subject_name}}</view>
							<view class="line"></view>
							</view>
						<!-- <view v-if="Subject_id == item.id" class="iconfont icon-dui1"></view> -->
					</view>
					<view class="class_child">
						<view @tap="tap_handle_choice_subject2(item2)" class="classtext_child" :class="Subject_id2 == item2.id ? 'active' : ''" v-for="(item2,index2) in item.childlist" :key="index2">
							{{item2.subject_name}}
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				list: [], //科目列表
				Subject_id: 0, //已选的科目id
				classifytype: 0,
				classlist: [], //科目2级列表
				
				Subject_id2: 0, //已选的科目id
			}
		},
		onShow() {
			// 获取科目列表
			this.getSub()
			// this.Subject_id = this.subject.id
			this.Subject_id2 = this.subject.id
		},
		computed: {
			...mapState(['subject', 'userinfo', 'subjectVip'])
		},
		methods: {
			async getSub() {
				let res = await this.$myHttp.post({
					url: this.$myHttp.urlMap.subjectList,
					data: {
						page: 1,
						limit: 0
					},
					needLogin: false
				})
				if (res.code === 1) {
					this.list = res.data
					this.classlist = this.list[0].childlist
				}
			},
			tap_handle_choice_subject(item){
				this.Subject_id = item.id
			},
			async tap_handle_choice_subject2(item) {
				this.$store.commit('setSubject', {
					subject: {
						id: item.id,
						subject_name: item.subject_name
					}
				})
				if (this.userinfo.user_id !== undefined) {
					await this.$myUserLogin.getSubvip(this.subject.id)
				}
				this.$myUtils.$router.switchTab({
					url: '/pages/index/index'
				})
			},
			changeclassify(index, id) {
				this.classifytype = index
				this.classlist = this.list[index].childlist
			}
		}
	}
</script>
<style lang="scss">
	page {
		background: #fff
	}

	.kaoshi-subject {
		display: flex;
		align-items: flex-start;
		background: #fff;
		height: 100vh;
	}

	.classifybox {
		width: 35%;
		background-color: #f6f9fc;
		height: 100vh;
		overflow: scroll;
	}

	.classify{
		display: flex;
		align-items: center;
		height: 50px;
	}
	.class {
		min-height: 50px;
	}

	.classifytext {
		margin-left: 15px;
		padding-left: 10px;
		font-size: 15px;
		line-height: 18px;
		border-left: 3px solid transparent;
		
		&.active{
			color: rgb(61,132,242);
		}
	}

	.classify.active {
		background-color: #fff;
	}

	.classify.active .classifytext {
		border-left: 3px solid #3a79f7;
	}

	.liebiaobox {
		width: 65%;
		height: 100vh;
		overflow: scroll;
	}

	.class {
		box-sizing: border-box;
		display: flex;
		align-items: center;
		flex-direction: column;
		padding: 0 15px;
		margin-top: 20rpx;
		font-size: 14px;
	}
	
	.classtext{
		margin-bottom: 10rpx;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		
		.line{
			background-color: rgb(229,229,229);
			height: 1px;
			width: 60rpx;
		}
		.text{
			margin: 0 20rpx;
			font-size: 30rpx;
		}
	}
	
	.classtext.active {
		font-weight: bold;
	}

	.icon-dui1 {
		color: #0ec380;
	}
	
	.class_child{
		width: 100%;
		box-sizing: border-box;
		padding: 10rpx 0;
		margin: 10rpx 0;
	}
	.classtext_child{
		box-sizing: border-box;
		padding: 36rpx 20rpx;
		width: 46%;
		margin: 0 2%;
		background-color: rgb(250,250,250);
		border-radius: 10rpx;
		text-align: center;
		color: rgb(108,108,108);
        display: inline-block;
		
		&.active{
			transition: all 0.3s;
			color: rgb(61,132,242);
		}
	}
</style>
